package com.ruoyi.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * 配置类
 * @ClassName WebConfig
 * @Description:
 * @Version 1.0
 * 2024/5/27 19:18
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Value("${domimage.uploaddir}")
    private String uploaddir;

    @Autowired
    private MinIOConfigProperties minIOConfigProperties;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //此处路径和上面的图片上传位置保持一致
        String prexypath = minIOConfigProperties.getPrexypath();
        int indexOfDoubleSlash = prexypath.indexOf("//");
        int indexOfFirstSlashAfterHost = prexypath.indexOf("/", indexOfDoubleSlash + 2);
        String substring = prexypath.substring(indexOfFirstSlashAfterHost);
        registry.addResourceHandler(substring+"**").addResourceLocations("file:" + uploaddir);
    }
}
